<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Gemlab &ndash; Documentation</title>
<link type="text/css" rel="stylesheet" href="static/style.css">
<link type="text/css" rel="stylesheet" href="static/prettify.css">
<script type="text/javascript" src="static/prettify.js"></script>
<script type="text/javascript" src="static/godocs.js"></script>
<script type="text/javascript" src="static/fixlnk.js"></script>
</head>
<body onload="prettyPrint()">
<div id="page">
<h1>Documentation for Developers</h1>

<h2>Table of Contents</h2>

<div id=nav></div>

<h2>Visualization toolkit</h2>

<p>This MechSys' module is a &quot;wrapper&quot; to <a href=http://www.vtk.org>the visualization toolkit
(VTK)</a>. This module provides a convenient set of C++ classes to generate 3D interactive drawings. The main
idea of this wrapper is to make VTK connections easier, for instance, when dealing with actors, renderers and
windows.  A simple example is (source: <a id=tdoc/doc_vtk1.cpp></a>:</p>

<pre class=prettyprint lang-cpp>
VTK::Axes   ax(/*scale*/1, /*hydroline*/true);
VTK::Arrow  ar(/*x*/Vec3_t(0.0,0.0,0.0), /*v*/Vec3_t(0.5,0.5,0.5));
VTK::Sphere sp(/*x*/Vec3_t(0.75,0.75,0.75), /*R*/0.25);
VTK::Cube   cu(/*Cen*/Vec3_t(0.0,0.0,0.0), /*lx*/1.0, /*ly*/1.0, /*lz*/1.0);
VTK::Win win;
ax.AddTo (win);
ar.AddTo (win);
sp.AddTo (win);
cu.AddTo (win);
win.Show();
</pre>

<p>With the following output:</p>
<p><a id=figs/doc_vtk1.png/200></a></p>

<p>Files: <a id=lib/vtk></a></p>



<h2>Mesh Generation</h2>

<p>Structured and unstructured meshes can be produced by MechSys. The results are stored in a <code
class=cls>Mesh::Generic</code> class. After an initial mesh is generated, a number of convenient
modifications are possible. For example, to convert a 3-node triangle mesh to 6-nodes or 15-nodes for FEM
analyses. Another set of very convenient methods are for characterizing the mesh topology, e.g. by finding
neighbours (vertices or cells). Methods to help with domain decomposition for parallel simulations are also
available.</p>

<p>Structured meshes can be created with 2D quads or 3D cubes using the <code class=cls>Mesh::Structured</code>
class. Unstructured meshes can be created with 2D triangles or 3D tetrahedra using the
<code class=cls>Mesh::Unstructured</code> class. The numbering convention for nodes, edges, and faces is shown
below for linear and quadratic elements:</p>

<p><img src=figs/meshelems1.png align=center /></p>

<p>Examples can be found in <a id=test/mesh01.cpp></a>.</p>

<p>Files: <a id=lib/mesh></a></p>


<h3>Generic</h3>

<p>Meshes can be created by adding vertices and cells, one after another, to the
<code class=cls>Mesh::Generic</code> class. In this way, different mesh generators can be developed taking
advantage of the code already implemented. An example is given below <a id=tdoc/doc_msh1.cpp></a>:</p>

<pre class=prettyprint lang-cpp>
Mesh::Generic mesh(/*NDim*/2);
mesh.SetSize   (6/*verts*/, 4/*cells*/);
mesh.SetVert   (0, -100, 0.0, 0.0, 0);
mesh.SetVert   (1, -101, 0.0, 2.0, 0);
mesh.SetVert   (2,    0, 2.0, 0.0, 0);
mesh.SetVert   (3,    0, 2.0, 1.5, 0);
mesh.SetVert   (4,    0, 4.0, 0.0, 0);
mesh.SetVert   (5,    0, 4.0, 1.0, 0);
mesh.SetCell   (0,   -1, Array<int>(0,2,3));
mesh.SetCell   (1,   -1, Array<int>(3,1,0));
mesh.SetCell   (2,   -1, Array<int>(2,4,5));
mesh.SetCell   (3,   -1, Array<int>(5,3,2));
mesh.SetBryTag (1, 0, -10);
mesh.SetBryTag (3, 0, -10);
mesh.WriteVTU  (&quot;doc_msh1&quot;);
mesh.WriteMPY  (&quot;doc_msh1&quot;);
</pre>

<p>After setting the number of vertices and cells, vertices and cells are set by
<code class=mth>SetVert</code> and <code class=mth>SetCell</code>, respectively. Vertices are set with their
ID (which must be sequential starting from 0), a negative integer representing their tag, and the x-y-z
coordinates (z is optional). Cells are set with their ID (sequential from 0), a tag number, and an array of
vertices IDs (connectivity). Boundary edges or faces can be tagged with the <code class=mth>SetBryTag</code>
method, which receives the cell ID, the edge/face number (see figure above), and a tag number. Output files
for <a href=http://www.paraview.org>Paraview</a> can be generated with the <code class=mth>WriteVTU</code>
method and a Python script for generating 2D drawings of the mesh with the <code class=mth>WriteMPY</code>
method. The resulting mesh is:</p>

<p><a id=figs/doc_msh1.png/200></a></p>


<h3>Structured</h3>

<p>Structured meshes are generated using the method of coordinates mapping. To do so, regions of the domain
are first defined in a <code class=bf>Mesh::Block</code> structure. In 2D, blocks can be 4-nodes or 8-nodes
quadrilaterals. The last one allow for the definition of nonlinear boundaries. In 3D, blocks can be
8-nodes or 20-nodes hexahedra. The last one allow for the definition of non-planar boundary surfaces. A
simple example is given below <a id=tdoc/doc_msh2.cpp></a>:</p>

<pre class=prettyprint lang-cpp>
Array<Mesh::Block> blks(2);
blks[0].Set(/*NDim*/2, /*Tag*/-1, /*NVert*/8,
            -1.,  1.0,                 0.0,
            -2.,  2.0,                 0.0,
            -3.,  2.0,                 2.0,
            -4.,  cos(PI/4.),          sin(PI/4.),
            -5.,  1.5,                 0.0,
            -6.,  2.0,                 1.0,
            -7.,  (SQ2+.5)*cos(PI/4.), (SQ2+.5)*sin(PI/4.),
            -8.,  cos(PI/8.),          sin(PI/8.),
            -10., -11., 0., -14.);
blks[1].Set(/*NDim*/2, /*Tag*/-1, /*NVert*/8,
            -4.,  cos(PI/4.),          sin(PI/4.),
            -3.,  2.0,                 2.0,
            -9.,  0.0,                 2.0,
            -10., 0.0,                 1.0,
            -7.,  (SQ2+.5)*cos(PI/4.), (SQ2+.5)*sin(PI/4.),
            -11., 1.0,                 2.0,
            -12., 0.0,                 1.5,
            -13., cos(3.*PI/8.),       sin(3.*PI/8.),
            0., -12., -13., -14.);
blks[0].SetNx (10);
blks[0].SetNy (10);
blks[1].SetNx (10);
blks[1].SetNy (10);
Mesh::Structured mesh(/*NDim*/2);
mesh.Generate (blks,/*O2*/false);
mesh.WriteMPY (doc_msh2, false, false, false);
</pre>

<p>The resulting mesh is:</p>

<p><a id=figs/doc_msh2.png/200></a></p>


<h3>Unstructured</h3>

<p>Unstructured meshes are generated using Delaunay triangulation. C++ structures wrapping
<a href=http://www.cs.cmu.edu/~quake/triangle.html>Triangle</a> and
<a href=http://tetgen.berlios.de/>Tetgen</a> are implemented in MechSys. The first step to generate an
unstructured mesh is to define closed domains, both for regions to be meshed and for regions representing
&quot;holes&quot;. A simple example is given below <a id=tdoc/doc_msh3.cpp></a>:</p>

<pre class=prettyprint lang-cpp>
Mesh::Unstructured mesh(/*NDim*/2);
mesh.Set    (8, 8, 1, 1);             // 8 points, 8 segmts, 1 reg, 1 hole
mesh.SetReg (0, -1, 0.005, 0.2, 0.8); // id, tag, max{area}, x, y *** regs
mesh.SetHol (0, 0.7, 0.7);            // id, x, y        *********** holes
mesh.SetPnt (0, -1, 0.0, 0.0);        // id, vtag, x, y  ********** points
mesh.SetPnt (1, -2, 1.5, 0.0);        // id, vtag, x, y
mesh.SetPnt (2, -3, 1.5, 1.5);        // id, vtag, x, y
mesh.SetPnt (3, -4, 0.0, 1.5);        // id, vtag, x, y
mesh.SetPnt (4,  0, 0.5, 0.5);        // id, vtag, x, y
mesh.SetPnt (5,  0, 1.0, 0.5);        // id, vtag, x, y
mesh.SetPnt (6,  0, 1.0, 1.0);        // id, vtag, x, y
mesh.SetPnt (7,  0, 0.5, 1.0);        // id, vtag, x, y
mesh.SetSeg (0, -10,  0, 1);          // id, etag, L, R  ******** segments
mesh.SetSeg (1, -20,  1, 2);          // id, etag, L, R
mesh.SetSeg (2, -30,  2, 3);          // id, etag, L, R
mesh.SetSeg (3, -40,  3, 0);          // id, etag, L, R
mesh.SetSeg (4,   0,  4, 5);          // id, etag, L, R
mesh.SetSeg (5,   0,  5, 6);          // id, etag, L, R
mesh.SetSeg (6,   0,  6, 7);          // id, etag, L, R
mesh.SetSeg (7,   0,  7, 4);          // id, etag, L, R
mesh.Generate ();
mesh.WriteMPY (doc_msh3, false, false, false);
</pre>

<p>The resulting mesh is:</p>

<p><a id=figs/doc_msh3.png/200></a></p>

</div><!-- page -->
<div id="footer">
<br /><br />
<hr>
<pre class="copyright">
Copyright (c) 2013 Sergio, Raul, Dorival. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
   * Neither the name of Dorival M Pedroso nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre><!-- copyright -->
</div><!-- footer -->
</body>
</html>
